package com.atx88;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class SettingAppActivity extends Activity {
	int DataPort = 8302;
	String groupip = "238.9.9.1";
	Button btnSearch = null;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//强制为横屏
        
        btnSearch = (Button)findViewById(R.id.btnSearch);
        btnSearch.setOnClickListener(clickListner);
    }
    
    OnClickListener clickListner = new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			if(v.getId() == R.id.btnSearch)
			{
				InetAddress remoteAddress = null;

				try {
					remoteAddress.getByName(groupip);
				} catch (UnknownHostException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				byte sendbuff[] = new byte[61];

				DatagramSocket datagramSocket = null;
				try {
					datagramSocket = new DatagramSocket(DataPort);
				} catch (SocketException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}	
				
				DatagramPacket  datagramPacket = new DatagramPacket(sendbuff, sendbuff.length);
				
				datagramPacket.setAddress(remoteAddress);
				datagramPacket.setPort(8302);
				datagramPacket.setLength(61);
				try {
					datagramSocket.send(datagramPacket);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			
		}
	};
}